package cmd

import (
	"fmt"
	"os"

	"github.com/spf13/cobra"

	config "code.alibaba-inc.com/agit/quarantine-helper/config"
	"code.alibaba-inc.com/agit/quarantine-helper/version"
)

var rootCmd = &cobra.Command{
	Use:     "quarantine-helper",
	Short:   "A simple tool to extract commits info in the phase of pre-receive hook.",
	Long:    `A simple tool to extract commits info in the phase of pre-receive hook.`,
	Version: version.Version(),
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
	if err := rootCmd.Execute(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}

func init() {
	rootCmd.PersistentFlags().StringVarP(&config.Repository, "repository", "r", os.Getenv(config.GitRepositoryPath), "path of repository")
	rootCmd.PersistentFlags().StringVarP(&config.Quarantine, "quarantine", "q", os.Getenv(config.GitQuarantinePath), "path of quarantine")
	rootCmd.PersistentFlags().BoolVarP(&config.FromWeb, "fromWeb", "w", false, "the commit is from web.")
}
